<?php

namespace Aspic\Event;

use Aspic\Exception;
use Aspic\Preset\OptionTrait;

class Event {

	use OptionTrait;

	protected $eventName;

	/**
	 * @var EventTriggerInterface The object that raised the event
	 */
	protected $subject;

	protected $_data;

	/**
	 *
	 * @param string $eventName
	 * @param array $data
	 * @param EventTriggerInterface $subject Object that raised the event (when there is one)
	 */
	public function __construct($eventName, array $data, EventTriggerInterface $subject = null) {
		if ($subject AND ! in_array($eventName, $subject->getEventsNames())) {
			throw new Exception(array(
			'Event "?" not registered on subject class "?". Available: ?',
			$eventName,
			get_class($subject),
			implode(', ', $subject->getEventsNames())
			));
		}

		$this->eventName = $eventName;
		$this->subject = $subject;
		$this->_data = $data;
	}

}
